<template lang="pug">
  div.back-btn-group
    Button(size='large',type='text',@click='backHome') 返回首页
    Button(size='large',type='text') 返回上一页({{second}}s)
</template>

<script>
export default {
  data() {
    return {
      second: 5,
      timer: null
    }
  },
  mounted() {
    this.timer = setInterval(() => {
      if (this.second === 0) this.backPrev()
      else this.second--
    }, 1000)
  },
  beforeDestroy() {
    clearInterval(this.timer)
  },
  methods: {
    backHome() {
      let homePage = ''
      if (JSON.parse(sessionStorage.getItem('routes'))[0].path === '') {
        homePage = JSON.parse(sessionStorage.getItem('routes'))[0].children[0].path
      } else {
        homePage = `${JSON.parse(sessionStorage.getItem('routes'))[0].path}/${JSON.parse(sessionStorage.getItem('routes'))[0].children[0].path}`
      }
      this.$router.push(`${homePage}`)
    },
    backPrev() {
      this.$router.go(-1)
    }
  }
}
</script>
